﻿using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Locates places near the given coordinates which are similar in name.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.GeoToolbox.bmp")]
    [Designer(typeof(GetSimilarPlacesDesigner))]
    [Description("Locates places near the given coordinates which are similar in name.")]
    public class GetSimilarPlaces : TwitterOperationInvoker<GeoSearchResult>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GetSimilarPlaces"/> class.
        /// </summary>
        public GetSimilarPlaces()
            : base("GetSimilarPlaces")
        { }

        /// <summary>
        /// The latitude to search around.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The latitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [RequiredArgument]
        [Description("The latitude to search around.")]
        public InArgument<string> Latitude { get; set; }

        /// <summary>
        /// The longitude to search around. 
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The longitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [RequiredArgument]
        [Description("The longitude to search around. ")]
        public InArgument<string> Longitude { get; set; }

        /// <summary>
        /// The name a place is known as.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [RequiredArgument]
        [Description("The name a place is known as.")]
        public InArgument<string> Name { get; set; }

        /// <summary>
        /// This is the place_id which you would like to restrict the search results to.
        /// </summary>
        /// <value>
        /// The contained within.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("This is the place_id which you would like to restrict the search results to.")]
        public InArgument<string> ContainedWithin { get; set; }

        /// <summary>
        /// This parameter searches for places which have this given street address.
        /// </summary>
        /// <value>
        /// The street address.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("This parameter searches for places which have this given street address.")]
        public InArgument<string> StreetAddress { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument latitudeArgument = new RuntimeArgument("Latitude", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Latitude, latitudeArgument);
            metadata.AddArgument(latitudeArgument);

            RuntimeArgument longitudeArgument = new RuntimeArgument("Longitude", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Longitude, longitudeArgument);
            metadata.AddArgument(latitudeArgument);

            RuntimeArgument nameArgument = new RuntimeArgument("Name", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Name, nameArgument);
            metadata.AddArgument(nameArgument);

            RuntimeArgument containedWithinArgument = new RuntimeArgument("ContainedWithin", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(ContainedWithin, containedWithinArgument);
            metadata.AddArgument(containedWithinArgument);

            RuntimeArgument streetAddressArgument = new RuntimeArgument("StreetAddress", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(StreetAddress, streetAddressArgument);
            metadata.AddArgument(streetAddressArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("latitude", Latitude);
            Parameters.Add("longitude", Longitude);
            Parameters.Add("name", Name);
            Parameters.Add("containedWithin", ContainedWithin);
            Parameters.Add("streetAddress", StreetAddress);

            base.Execute(context);
        }

    }
}
